package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.DecimalFormat;
import java.util.*;
import javax.swing.*;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.SimpleAttributeSet;
import java.awt.*;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.text.StyleContext;

import com.tool.role.RoleData;
import org.come.Frame.MsgJframe;
import org.come.bean.Skill;
import org.come.entity.Goodstable;
import org.come.until.*;

import com.tool.role.BaseXingpans;
import com.tool.role.RoleProperty;
import com.tool.tcpimg.UIUtils;

/**
 * 	星盘炼化属性面板
 */
public class XingPanSXJpanel extends JPanel {
	private JLabel labtext1,labtext2,labskill;//
	private List<String> xpkxList = new ArrayList<String>(16);
	private JLabel[] xpsxz = new JLabel[16];
	private Goodstable good;
	public XingPanSXJpanel() {

		this.setPreferredSize(new Dimension(400, 340));
		this.setLayout(null);
		this.setBackground(UIUtils.Color_BACK);

		labtext1 = new JLabel();
		labtext1.setForeground(Color.YELLOW);
		labtext1.setFont(UIUtils.TEXT_HYK20);
		labtext1.setBounds(140, 0, 250, 50);
		labtext1.setText("星盘炼化属性");
		this.add(labtext1);
		labtext2 = new JLabel();
		labtext2.setForeground(UIUtils.COLOR_SIGN);
		labtext2.setFont(UIUtils.TEXT_HY88);
		labtext2.setBounds(165, 310-75, 250, 50);
		labtext2.setText("星盘技能");
		this.add(labtext2);

		labskill = new JLabel();
		labskill.setBounds(175, 310-35, 50, 50);
		labskill.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {
				if (labskill.isVisible()) {
					Skill skill = UserMessUntil.getskill1(labskill.getText());
					if (skill == null) {
						return;
					}
					MsgJframe
							.getJframe()
							.getJapnel()
							.SM2(skill);
				}
			}
			@Override
			public void mouseExited(MouseEvent e) {
				FormsManagement.HideForm(46);
			}
		});
		this.add(labskill);

		for(int i=0;i<16;i++){
			int x = 15;
			int y = i;
			if(i>7){
				x = 205;
				y = i-8;
			}
			xpsxz[i] = new JLabel();
			xpsxz[i].setForeground(UIUtils.COLOR_TEXT1);
			xpsxz[i].setFont(UIUtils.TEXT_FONT1);
			xpsxz[i].setBounds(x , 30+25 * y, 250, 50);
			this.add(xpsxz[i]);
		}
		getXpkx();
	}

	private ImageIcon icon = CutButtonImage.getImage("img/xy2uiimg/tishikuang.png", 400, 340);
	private ImageIcon imgSkill;
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.drawImage(icon.getImage(), 0, 0, 400, 340, this);

	}

	public void getXpkx() {
		xpkxList = new Vector<String>();
		Vector<BaseXingpans> xingpansVector = RoleProperty.getRoleProperty().xingpanVector;
		if(xingpansVector!=null) {
			Collections.sort(xingpansVector, new Comparator<BaseXingpans>() {
	            @Override
	            public int compare(BaseXingpans o1, BaseXingpans o2) {
	                return Integer.compare(o1.getBh(), o2.getBh());
	            }
	        });
			for (int z = 0; z < xingpansVector.size(); z++) {
				BaseXingpans baseXingpans = xingpansVector.get(z);
				DecimalFormat df = new DecimalFormat("#.00");
				String formattedNumber = df.format(baseXingpans.getKeyValue());
				String formattedNumber1 = df.format(baseXingpans.getKeyValue1());
				double result = Double.parseDouble(formattedNumber);
				double result1 = Double.parseDouble(formattedNumber1);

				String bh = baseXingpans.getBh()+"号星盘："+baseXingpans.getKey() +":"+result;
				xpkxList.add(bh);
				String bh1 = "        "+baseXingpans.getKey1() +":"+result1;
				xpkxList.add(bh1);
			}
		}
        if(xpkxList!=null && xpkxList.size()>0) {
        	for(int i=0;i<xpkxList.size();i++) {
				if(xpkxList.get(i).split("：").length>1){
					String coloredText =xpkxList.get(i).split("：")[0];
					String restOfText =xpkxList.get(i).split("：")[1];
					String htmlText = "<html><body><font color='#FF7F00'>" + coloredText + "</font>:" + restOfText + "</body></html>";
					xpsxz[i].setText(htmlText);
				}else{
					xpsxz[i].setText(xpkxList.get(i));
				}
        	}
        }
		String[] skill = RoleData.getRoleData().getPrivateData().getSkill("X");
		if(skill!=null && skill.length>0){
			Skill skill1 = UserMessUntil.getSkillId(skill[0].split("_")[0]);
			labtext2.setVisible(true);
			imgSkill = CutButtonImage.getImage("inkImg/old/skill/fighting-skill/" + skill[0].split("_")[0] + ".png", 50, 50);
			labskill.setIcon(imgSkill);
			labskill.setText(skill1.getSkillname());
		}else{
			labtext2.setVisible(false);
		}
	}
	public Goodstable getGood() {
		return good;
	}
	public void setGood(Goodstable good) {
		this.good = good;
	}

	public JLabel getLabskill() {
		return labskill;
	}

	public void setLabskill(JLabel labskill) {
		this.labskill = labskill;
	}
}
